a = open('BMR data.txt', 'a+')
while True:
    import time
    b = time.strftime("\n%y-%m%d %H:%M:%S\n")
    print(time.strftime("%y-%m%d %H:%M:%S"))
    print("请输入以下信息，并用空格分割")
    bmr1, bmr2 = "", ""

    try:
        input_str = input("性别 体重（kg) 身高（cm） 年龄:")
        str_list = input_str.split(' ')
        gender = str_list[0]
        weight = float(str_list[1])
        height = float(str_list[2])
        age = int(str_list[3])

        if (gender == '男') or (gender == 'man'):
            bmr2 = 13.7 * weight + 5.0 * height - 6.8 * age + 66
            bmr1 = 10 * weight + 6.25 * height - 5 * age + 5
            c = "您的性别：{0}，体重：{1}公斤，身高{2}厘米，年龄{3}岁\n".format(gender, weight, height, age)
            d = "BMR='{0}',BMR(美国标准）='{1}'\n".format(bmr1, bmr2)
            print(c)
            print(d)
            a.write(b+c+d)

        elif (gender == '女') or (gender == 'woman'):
            bmr2 = 9.6 * weight + 1.8 * height - 4.7 * age + 655
            bmr1 = 10 * weight + 6.25 * height - 5 * age - 161
            c = "您的性别：{0}，体重：{1}公斤，身高{2}厘米，年龄{3}岁\n".format(gender, weight, height, age)
            d = "BMR='{0}',BMR(美国标准）='{1}'\n".format(bmr1, bmr2)
            print(c)
            print(d)
            a.write(b+c+d)

        else:
            print('性别填写有误')

    except ValueError:
        print('年龄须为整数')
    except IndexError:
        print('输入的信息过少')
    except:
        print('程序异常！')

    print()
    y_or_n = input('是否退出程序（是/否)')
    if y_or_n == "是":
        print("结束运行")
        break
a.close()